<template>
    <h2>投资项目信息修改</h2>
    <table border="1">
        <tr>
            <td>投资名称</td>
            <td><input type="text" v-model="info.I_Name"></td>
        </tr>
        <tr>
            <td>投资总额度</td>
            <td><input type="text" v-model="info.I_Budget"></td>
        </tr>
        <tr>
            <td>
                <button @click="editData">修改</button>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { ref, onMounted } from 'vue'
import axios from 'axios';

// 获取路由参数
const route = useRoute()
// 获取路由实例
const router = useRouter()

//创建响应式对象
const info = ref({
    I_Id: 0,
    I_Name: '',
    I_Budget: ""
})


//创建周期对象实例
onMounted(() => {
    loadDate();
})
// 加载数据
const loadDate = () => {
    // 发送请求获取数据
    axios.get('https://localhost:44387/api/Invests/GetInvestInfo', {
        params: {
            I_Id: route.query.I_Id
        }
    }).then(function (res) {
        console.log(res.data);
        info.value = res.data;
    })
}
//实现修改
const editData = () => {
    axios.put('https://localhost:44387/api/Invests/EditInvestInfo', {
        I_Id: route.query.I_Id,
        I_Name: info.value.I_Name,
        I_Budget: info.value.I_Budget
    })
        .then(res => {
            console.log(res.data);
            if (res.data > 0) {
                alert("投资项目信息修改成功");
                
            }
            else if (res.data == -1) {
                alert("有人投资的项目无法修改");
            }
            else {
                alert("投资项目信息修改失败");
            }
            // 跳转到投资项目信息列表页面
            router.push('/ShowInvestInfo')
        })
        .catch(err => {
            console.log(err);
        })

}
</script>
